<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>插槽2</h2>
      <!-- 动态插槽名用于同一块内容在子组件不同的位置显示 -->
      <child>
        <template #[str]>
          <span>123</span>
        </template>
      </child>

      <hr />

      <!-- 作用域插槽的作用就是让父组件传入的值可以使用子组件的变量 -->
      <!-- <child2 v-slot="slotProps"> {{ slotProps.nickname }} </child2> -->
      <child2 v-slot="{nickname}"> {{ nickname }} </child2>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const Child = {
        template: `
          <div>
            <slot name="left"></slot>
            <div>这是child子组件</div>
            <slot name="right"></slot>
          </div>
        `,
      };

      const Child2 = {
        data() {
          return {
            name: "laotian",
          };
        },
        template: `
          <div>这是child2子组件</div>
          <slot :nickname="name"></slot>
        `,
      };

      Vue.createApp({
        data() {
          return {
            str: "left",
          };
        },
        components: {
          Child,
          Child2,
        },
      }).mount("#app");
    </script>
  </body>
</html>
